package com.icloud.cer.rest.util;

import java.net.SocketAddress;

import org.apache.mina.core.session.IoSession;
import org.slf4j.Logger;

import com.icloud.cer.rest.msg.MsgConstants;

public class LogUtils {
	
	public static void printMessage(Logger log, short command, IoSession session) {
		StringBuffer sb = new StringBuffer();
		sb.append("[").append(command).append("]");
		switch (command) {
		case MsgConstants.CLIENT_REQ_REG:
			sb.append("接收客户端注册请求 ");
			log.info(" " + command);
			break;
		case MsgConstants.SERVER_RES_REG:
			sb.append("响应客户端注册请求 ");
			break;
		case MsgConstants.SERVER_REQ_HEARTBEAT:
			sb.append("服务器发送心跳请求 ");
			break;
		case MsgConstants.CLIENT_RES_HEARTBEAT:
			sb.append("客户端响应心跳请求 ");
			break;
		case MsgConstants.CLIENT_REQ_ENCRYPT:
			sb.append("客户端请求加密任务 ");
			break;
		case MsgConstants.SERVER_SENT_ENCRYPT:
			sb.append("服务器发送加密任务 ");
			break;
		case MsgConstants.CLIENT_RES_ENCRYPT:
			sb.append("客户端返回加密结果 ");
			break;
		default:
			sb.append("不合法的command:" + command);
			log.error(sb.toString());
			return;
		}
		SocketAddress ra = session.getRemoteAddress();
		sb.append(session.getId()).append(" ");
		sb.append(ra.toString());
		log.info(sb.toString());
	}
}
